﻿/*
 * Copyright 2009, Payton Byrd
 * Licensed Under the Microsoft Public License (MS-PL)
 */

using PaytonByrd.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;

namespace PaytonByrd.Extensions.UnitTests
{
    
    
    /// <summary>
    ///This is a test class for ValidationExtensionsTest and is intended
    ///to contain all ValidationExtensionsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ValidationExtensionsTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for IsNullOrEmpty
        ///</summary>
        [TestMethod()]
        public void StringIsNullOrEmptyTest()
        {
            string value = null; 
            bool expected = true; 
            bool actual;
            actual = value.IsNullOrEmpty();
            Assert.AreEqual(expected, actual, "Testing for null.");
            value = string.Empty;
            actual = value.IsNullOrEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            expected = false;
            actual = "Test".IsNullOrEmpty();
            Assert.AreEqual(expected, actual, "Testing non-empty.");
        }

        /// <summary>
        ///A test for IsNull
        ///</summary>
        [TestMethod()]
        public void IsNullTest()
        {
            object value = null; 
            bool expected = true; 
            bool actual;
            actual = value.IsNull();
            Assert.AreEqual(expected, actual, "Testing for null.");
            value = new object();
            actual = value.IsNull();
            Assert.AreNotEqual(expected, actual, "Testing for not null.");
        }

        /// <summary>
        ///A test for IsNotNull
        ///</summary>
        [TestMethod()]
        public void IsNotNullTest()
        {
            object value = null; 
            bool expected = false; 
            bool actual;
            actual = value.IsNotNull();
            Assert.AreEqual(expected, actual, "Testing for null.");
            value = new object();
            actual = value.IsNotNull();
            Assert.AreNotEqual(expected, actual, "Testing for not null.");
        }

        /// <summary>
        ///A test for IsNotEmpty
        ///</summary>
        [TestMethod()]
        public void ICollectionIsNotEmptyTest()
        {
            ICollection collection = new ArrayList(); 
            bool expected = false; 
            bool actual;
            actual = collection.IsNotEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            ((ArrayList)collection).Add(new object());
            actual = collection.IsNotEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        /// <summary>
        ///A test for IsNotEmpty
        ///</summary>
        [TestMethod()]
        public void ArrayIsNotEmptyTest()
        {
            Array array = new string[0]; 
            bool expected = false; 
            bool actual;
            actual = array.IsNotEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            array = new string[1];
            actual = array.IsNotEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        /// <summary>
        ///A test for IsNotEmpty
        ///</summary>
        [TestMethod()]
        public void StringIsNotEmptyTest()
        {
            string value = string.Empty; 
            bool expected = false; 
            bool actual;
            actual = value.IsNotEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty");
            actual = "Test".IsNotEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        /// <summary>
        ///A test for IsNotEmpty
        ///</summary>
        public void GenericICollectionIsNotEmptyTestHelper<T>()
        {
            ICollection<T> collection = new List<T>(); 
            bool expected = false; 
            bool actual;
            actual = collection.IsNotEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            ((List<T>)collection).Add(default(T));
            actual = collection.IsNotEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        [TestMethod()]
        public void GenericICollectionIsNotEmptyTest()
        {
            GenericICollectionIsNotEmptyTestHelper<GenericParameterHelper>();
        }

        /// <summary>
        ///A test for IsNotEmpty
        ///</summary>
        public void GenericIDictionaryIsNotEmptyTestHelper<K, T>()
            where K : new()
        {
            IDictionary<K, T> collection = new Dictionary<K, T>(); 
            bool expected = false; 
            bool actual;
            actual = collection.IsNotEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            collection.Add(
                new K(), 
                default(T));
            actual = collection.IsNotEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        [TestMethod()]
        public void GenericIDictionaryIsNotEmptyTest()
        {
            GenericIDictionaryIsNotEmptyTestHelper<GenericParameterHelper, GenericParameterHelper>();
        }

        /// <summary>
        ///A test for IsNotEmpty
        ///</summary>
        public void GenericIListIsNotEmptyTestHelper<T>()
        {
            IList<T> collection = new List<T>(); 
            bool expected = false; 
            bool actual;
            actual = collection.IsNotEmpty();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void GenericIListIsNotEmptyTest()
        {
            GenericIListIsNotEmptyTestHelper<GenericParameterHelper>();
        }

        /// <summary>
        ///A test for IsNotEmpty
        ///</summary>
        [TestMethod()]
        public void IDictionaryIsNotEmptyTest()
        {
            IDictionary collection = new Dictionary<string, string>(); 
            bool expected = false; 
            bool actual;
            actual = collection.IsNotEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            collection.Add(
                string.Empty,
                string.Empty);
            actual = collection.IsNotEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        /// <summary>
        ///A test for IsNotEmpty
        ///</summary>
        public void DataTableIsNotEmptyTestHelper<DR>()
            where DR : DataRow
        {
            DataTable table = new DataTable();
            table.Columns.Add(new DataColumn("Test", typeof(string)));
            bool expected = false;
            bool actual;

            actual = table.IsNotEmpty<DR>();
            Assert.AreEqual(expected, actual, "Testing for empty.");

            DR newRow = (DR)table.NewRow();
            newRow["Test"] = "Test Value";
            table.Rows.Add(expected);

            actual = table.IsNotEmpty<DR>();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");

        }

        [TestMethod()]
        public void DataTableIsNotEmptyTest()
        {
            DataTableIsNotEmptyTestHelper<DataRow>();
        }

        /// <summary>
        ///A test for IsNotEmpty
        ///</summary>
        [TestMethod()]
        public void IListIsNotEmptyTest()
        {
            IList collection = new List<string>();
            bool expected = false;
            bool actual;
            actual = collection.IsNotEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            collection.Add("test");
            actual = collection.IsNotEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        /// <summary>
        ///A test for IsEmpty
        ///</summary>
        [TestMethod()]
        public void ICollectionIsEmptyTest()
        {
            ICollection collection = new List<string>();
            bool expected = false;
            bool actual;
            actual = collection.IsNotEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            ((IList)collection).Add("test");
            actual = collection.IsNotEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        /// <summary>
        ///A test for IsEmpty
        ///</summary>
        [TestMethod()]
        public void StringIsEmptyTest()
        {
            string value = string.Empty; 
            bool expected = true; 
            bool actual;
            actual = value.IsEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            actual = "test".IsEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        /// <summary>
        ///A test for IsEmpty
        ///</summary>
        public void GenericIListIsEmptyTestHelper<T>()
        {
            IList<T> collection = new List<T>(); 
            bool expected = true; 
            bool actual;
            actual = collection.IsEmpty();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void GenericIListIsEmptyTest()
        {
            GenericIListIsEmptyTestHelper<GenericParameterHelper>();
        }

        /// <summary>
        ///A test for IsEmpty
        ///</summary>
        public void GenericIDictionaryIsEmptyTestHelper<K, T>()
            where K : new()
        {
            IDictionary<K, T> collection = new Dictionary<K, T>();
            bool expected = true;
            bool actual;
            actual = collection.IsEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            collection.Add(
                new K(),
                default(T));
            actual = collection.IsEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        [TestMethod()]
        public void GenericIDictionaryIsEmptyTest()
        {
            GenericIDictionaryIsEmptyTestHelper<GenericParameterHelper, GenericParameterHelper>();
        }

        /// <summary>
        ///A test for IsEmpty
        ///</summary>
        [TestMethod()]
        public void ArrayIsEmptyTest()
        {
            Array array = new string[0]; 
            bool expected = true; 
            bool actual;
            actual = array.IsEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            array = new string[1];
            actual = array.IsEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        /// <summary>
        ///A test for IsEmpty
        ///</summary>
        public void DataTableIsEmptyTestHelper<DR>()
            where DR : DataRow
        {
            DataTable table = new DataTable(); 
            bool expected = true; 
            bool actual;
            actual = table.IsEmpty<DR>();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            table.Rows.Add(table.NewRow());
            actual = table.IsEmpty<DR>();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        [TestMethod()]
        public void DataTableIsEmptyTest()
        {
            DataTableIsEmptyTestHelper<DataRow>();
        }

        /// <summary>
        ///A test for IsEmpty
        ///</summary>
        public void GenericICollectionIsEmptyTestHelper<T>()
        {
            ICollection<T> collection = new List<T>(); 
            bool expected = true; 
            bool actual;
            actual = collection.IsEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            ((IList<T>)collection).Add(default(T));
            actual = collection.IsEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        [TestMethod()]
        public void GenericICollectionIsEmptyTest()
        {
            GenericICollectionIsEmptyTestHelper<GenericParameterHelper>();
        }

        /// <summary>
        ///A test for IsEmpty
        ///</summary>
        [TestMethod()]
        public void IListIsEmptyTest()
        {
            IList collection = new List<string>();
            bool expected = true;
            bool actual;
            actual = collection.IsEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            ((IList<string>)collection).Add(string.Empty);
            actual = collection.IsEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        /// <summary>
        ///A test for IsEmpty
        ///</summary>
        [TestMethod()]
        public void IDictionaryIsEmptyTest()
        {
            IDictionary collection = new Dictionary<string, string>(); 
            bool expected = true; 
            bool actual;
            actual = collection.IsEmpty();
            Assert.AreEqual(expected, actual, "Testing for empty.");
            collection.Add(string.Empty, string.Empty);
            actual = collection.IsEmpty();
            Assert.AreNotEqual(expected, actual, "Testing for not empty.");
        }

        /// <summary>
        ///A test for AssertParameterNotNull
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void AssertParameterNotNullTest()
        {
            object value = new object(); 
            string message = "Value is null"; 
            string name = "value";
            value.AssertParameterNotNull(message, name);
            value = null;
            value.AssertParameterNotNull(message, name);
        }

        /// <summary>
        ///A test for AssertParameterNotEmpty
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentException))]
        public void AssertParameterNotEmptyTest()
        {
            string value = "test"; 
            string message = string.Empty; 
            string name = string.Empty;
            value.AssertParameterNotEmpty(message, name);
            value = string.Empty;
            value.AssertParameterNotEmpty(message, name);
        }

        /// <summary>
        ///A test for AssertEquals
        ///</summary>
        public void AssertEqualsTestHelper<ExceptionType>()
            where ExceptionType : Exception
        {
            object value = 1; 
            object compareTo = 1; 
            string message = "Are not equals.";
            value.AssertEquals<ExceptionType>(compareTo, message);
            value = string.Empty;
            value.AssertEquals<ExceptionType>(compareTo, message);
        }

        [TestMethod()]
        [ExpectedException(typeof(ApplicationException))]
        public void AssertEqualsTest()
        {
            AssertEqualsTestHelper<ApplicationException>();
        }
    }
}
